package database;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import messages.MessageLogoutReply.ErrMsg;
import messages.MessageLogoutReply.LogoutStatus;

/**
 * 
 *  Log Out The User
 * 	
 * @author Amir S.
 * @author Jacob C.
 * @author Maya G.
 * @author Michael V.
 *
 */

public class LogOut {

	
	private String userID;
	private LogoutStatus status;
	private ErrMsg error;
	private int num;

	public LogOut(){
		
	}
	
	/**
	 * 
	 * @param user
	 * @param num
	 */
	
	public LogOut(String user, int num){
		
		this.userID = user;
		this.num = num;
	}
	
	/**
	 * 
	 * @throws SQLException
	 */
	
	public void makeLogOut() throws SQLException{
		
		String user;
			
		
		Statement stmt;
		

			if(num == 1){
				JDBC.updateStatment("users", "userLogged", "0", "userId", userID);
				status=LogoutStatus.LOGGED_OUT;
			}
			else{
			status=LogoutStatus.LOGOUT_FAIL;
			error=ErrMsg.NO_CONNECTION;
			}

	}
	
	/**
	 * 
	 * @throws SQLException
	 */
	
	public void makeLogEveryoneOut() throws SQLException{				
		
		JDBC.updateStatmentCloumn("users", "userLogged","0");
		System.out.println("All users login status has been set to 0.");
	}
	
	/**
	 * 
	 * @return
	 */
	
	public String getUserID(){
		return userID;
		
	}
	
	/**
	 * 
	 * @return LogoutStatus status
	 */
	
	public LogoutStatus getLogoutStatus() {
		return status;
	}
	
	/**
	 * 
	 * @return error message
	 */
	
	public ErrMsg getErrorMsg() {
		return error;
	}
}